package xq.gwt.ui.widgets.factory;

import xq.gwt.mvc.model.EntityModel;
import xq.gwt.ui.crud.EntityDetailEditor;
import xq.gwt.ui.crud.EntityEditorModel;
import xq.gwt.ui.widgets.entity.FormEntityPresenter;

public class DefaultEntityPresenterFactory implements EntityPresenterFactory{

	public FormEntityPresenter buildPresenter(EntityModel forEntity){
		EntityDetailEditor entityEditor = new EntityDetailEditor();
		if(forEntity instanceof EntityEditorModel){
			EntityEditorModel editorModel = (EntityEditorModel)forEntity;
			if(editorModel.getPropertyGroups() != null){
				entityEditor.setPropertyGroups(editorModel.getPropertyGroups());
			}			
		}
		entityEditor.setEntity(forEntity);
		
		return entityEditor;
	}
}
